// These files are basically RAW files
file_extension_to_open = ".f32";
// Path on my home Desktop
pathToImg   = "D:\\My Documents\\My Dropbox\\School\\PILOT\\_htdocs\\Images\\Samples\\";
//saveImgPath = "/home/jfrank3/www-home/imagerecon/Images/";
//saveImgName = "stack_from_resampled_RAW.zip";
//saveImgType = "ZIP";
scale       = 2;

// Raw opening paramaters - examples and order of args listed below - vals will be overridden by passed-in vals
rawImgType = "32-bit Real";
rawWidth   = 560;
rawHeight  = 560;
rawOffset  = 0;
rawNumImgs = 1;
rawGapBetweenImgs = 0;
// NOTE:  Add the boolean directive arg: "little-endian" for these "f32" images




// Trying to fix the Little-Endian issue by making saves also use Little-Endian
// the "save" option enables "Save TIFF and Raw in Intel Byte Order", which saves using little-endian byte order
//run("Input/Output...", "jpeg=75 gif=-1 file=.txt save copy_row save_column save_row");  




// Get a list of all files in dir
images_to_open = getFileList(pathToImg);

// Open all imgs
for( i = 0; i < images_to_open.length; i++ ) {
	if(endsWith(images_to_open[i], file_extension_to_open)) {
		// Import the raw file
			//run("Raw...", "open=[" + pathToImg + images_to_open[i] +"] image=[16-bit Unsigned] width=1024 height=768 offset=0 number=1 gap=0");
		run("Raw...", "open=[" + pathToImg + images_to_open[i] +"] image=[" + rawImgType + "] "
		                   + "width="   + rawWidth   + " height=" + rawHeight + " offset=" + rawOffset
		                   + " number=" + rawNumImgs + " gap="    + rawGapBetweenImgs
		                   //);
		                   + " little-endian");
	}
}
/*
// Downsample imgs (in prep of sending the stack to the client for previewing)
for( i = 0; i < images_to_open.length; i++ ) {
	if(endsWith(images_to_open[i], file_extension_to_open)) {
		selectWindow(images_to_open[i]);
		      //run("Resample", "factor=4 factor=4 factor=4");
		
		// Need to convert from 32-bit to 16-bit in order for Resample command to work on these 32-bit imgs
		run("16-bit");
		
		run("Resample", "factor=" + scale + " factor=" + scale + " factor=" + scale);
	}
}

// Create the stack from all open images - first close the orig (full-sized) img windows so we don't stack them
for( i = 0; i < images_to_open.length; i++ ) {
	if(endsWith(images_to_open[i], file_extension_to_open)) {
		selectWindow(images_to_open[i]);
		close();
	}
}
*/
run("Images to Stack", "name=[] title=[] use keep");
saveAs("ZIP", "D:\\My Documents\\My Dropbox\\School\\PILOT\\_htdocs\\Images\\Samples\\Stack_F32_littleEndianOpeningOnly.zip");
